local IngredientLeafNote=Ingredient("aip_leaf_note",1,"images/inventoryimages/aip_leaf_note.xml")

local inscriptions={
aip_dou_fire_inscription={ tag="FIRE",recipes={ IngredientLeafNote,Ingredient("log",1),} },
aip_dou_ice_inscription={ tag="ICE",recipes={ IngredientLeafNote,Ingredient("log",1),} },
aip_dou_sand_inscription={ tag="SAND",recipes={ IngredientLeafNote,Ingredient("log",1),} },
aip_dou_heal_inscription={ tag="HEAL",recipes={ IngredientLeafNote,Ingredient("log",1),} },
aip_dou_follow_inscription={ tag="FOLLOW",recipes={ IngredientLeafNote,Ingredient("log",1),} },
aip_dou_through_inscription={ tag="THROUGH",recipes={ IngredientLeafNote,Ingredient("log",1),} },
aip_dou_area_inscription={ tag="AREA",recipes={ IngredientLeafNote,Ingredient("log",1),} },
aip_dou_split_inscription={ tag="SPLIT",recipes={ IngredientLeafNote,Ingredient("log",1),} },
}

local categories={
FIRE="element",
ICE="element",
SAND="element",
HEAL="element",
FOLLOW="action",
THROUGH="action",
AREA="action",
SPLIT="split",
}

local damages={
FIRE=5,
ICE=20,
SAND=10,
HEAL=25,
PLANT=5,
SPLIT=0.01,
}

local defaultColor={ 0.6,0.6,0.6,0.1 }

local colors={
FIRE={ 1,0.8,0,1 },
ICE={ 0.2,0.4,1,1 },
SAND={ 1,0.8,0.1,1 },
HEAL={ 0,0.6,0.1,0.5 },
PLANT={ 0,0.6,0.1,0.5 },
}

local function getType(item)
local type=categories[item._douTag]
return { name=item._douTag,type=type }
end

local function createGroup(prevGrp)
local prev=prevGrp or {}

return {

action=nil,

element=prev.element or nil,

elementCount=0,

damage=math.max((prev.damage or 0)*0.75,5),

color=prev.color or defaultColor,

split=0,
}
end

function calculateProjectile(items)
local projectileInfo={
action=nil,
uses=1,
queue={},
}






local flattenItems=aipFlattenTable(items)

if #flattenItems==0 then
projectileInfo.queue={ createGroup() }
else
local group=nil
local prevGroup=nil

for i,item in pairs(flattenItems) do
if group==nil then
group=createGroup(prevGroup)
end

if item~=nil then
local typeInfo=getType(item)
local damage=group.damage+(damages[typeInfo.name] or 5)

if typeInfo.type=="element" then

if group.element~=typeInfo.name then
group.elementCount=0
end

group.element=typeInfo.name
group.elementCount=group.elementCount+1
group.damage=group.damage+damage
group.color=colors[typeInfo.name] or defaultColor


projectileInfo.uses=projectileInfo.uses+1

elseif typeInfo.type=="split" then
group.split=group.split+1
group.damage=group.damage+damage

elseif typeInfo.type=="action" then

group.action=typeInfo.name
group.damage=group.damage+damage

table.insert(projectileInfo.queue,group)
prevGroup=group
group=nil


projectileInfo.uses=projectileInfo.uses+2
end
end
end


if group~=nil then
table.insert(projectileInfo.queue,group)
end
end


projectileInfo.action=projectileInfo.queue[1].action or "LINE"

return projectileInfo
end

return {
calculateProjectile=calculateProjectile,
inscriptions=inscriptions,
}